package com.example.administrator.xmut.kcb;

import java.sql.Date;
import java.util.Calendar;
import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

public class MyPagerAdapter extends PagerAdapter {
	private List<View> view_list;
	private String[] title_list;
	public int today=getWeekOfDate(null);
	public MyPagerAdapter(List<View> view_list) {
		this.view_list = view_list;
		if(today==1)title_list = new String[]{"周一","周二","周三","周四","周五","周六","周日"};
		if(today==2)title_list = new String[]{"周二","周三","周四","周五","周六","周日","周一"};
		if(today==3)title_list = new String[]{"周三","周四","周五","周六","周日","周一","周二"};
		if(today==4)title_list = new String[]{"周四","周五","周六","周日","周一","周二","周三"};
		if(today==5)title_list = new String[]{"周五","周六","周日","周一","周二","周三","周四"};
		if(today==6)title_list = new String[]{"周六","周日","周一","周二","周三","周四","周五"};
		if(today==0)title_list = new String[]{"周日","周一","周二","周三","周四","周五","周六"};
	}

	@Override
	public int getCount() {
		return view_list.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		container.addView(view_list.get(position));
		return view_list.get(position);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(view_list.get(position));
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return title_list[position];
	}


	public static int getWeekOfDate(Date date) {
		Calendar calendar = Calendar.getInstance();
		if(date != null){
			calendar.setTime(date);
		}
		int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0){
			w = 0;
		}
		return w;
	}
}
